import { JupiterRole, JupiterRoleQuery } from '../types/roleTypes';
import request from 'utils/request';

// 获取角色列表
export const fetchRoleList = (params: JupiterRoleQuery) => {
  return request.post('/roles/page', params);
};

// 获取所有角色
export const fetchAllRoles = () => {
  return request.get('/roles');
};

// 根据UUID获取角色
export const fetchRoleById = (uuid: string) => {
  return request.get(`/roles/${uuid}`);
};

// 创建角色
export const createRole = (data: Partial<JupiterRole>) => {
  return request.post('/roles', data);
};

// 更新角色
export const updateRole = (uuid: string, data: Partial<JupiterRole>) => {
  return request.put(`/roles/${uuid}`, data);
};

// 删除角色
export const deleteRole = (uuid: string) => {
  return request.delete(`/roles/${uuid}`);
};

// 更新角色状态
export const updateRoleStatus = (uuid: string, status: number) => {
  return request.put(`/roles/${uuid}/status?status=${status}`);
};

// 根据用户ID获取角色列表
export const fetchRolesByUserId = (userId: string) => {
  return request.get(`/roles/user/${userId}`);
};

// 检查角色编码是否存在
export const checkRoleCode = (roleCode: string) => {
  return request.get(`/roles/check/roleCode?roleCode=${roleCode}`);
};

export const getRolePermissionsService = (uuid: string) => {
  return request.get(`/role-permissions/role/${uuid}`);
};

export const getPermissionTreeService = () => {
  return request.get(`/permissions/tree`);
};

export const updateRolePermissionsService = (data: any) => {
  return request.post(`/role-permissions/assign-permissions-to-role`, data);
};

// 根据用户ID获取角色列表
export const getAllActiveRolesService = () => {
  return request.get(`/roles/getAllActiveRoles`);
};

export const restoreRole = (uuid: string) => {
  return request.post(`/roles/restoreRole/${uuid}`, {});
};
